using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using Gameplay;


public class FindPlayerInMap : Conditional
{
	public float Distance;
    public SharedTransform PlayerTransform;
	public override TaskStatus OnUpdate()
	{
        BehaviorTree behaviorTree = GetComponent<BehaviorTree>();

        var player = GameObject.FindObjectOfType<PlayerController>();
		if (player == null)
		{
			return TaskStatus.Failure;
		}
        if (Vector3.Distance(new Vector3(player.transform.position.x, 0, player.transform.position.z), new Vector3(transform.position.x, 0, transform.position.z)) <= Distance)
        {
            PlayerTransform.SetValue(player.transform);
            behaviorTree.SetVariableValue("TargetTransform", player.transform);
            return TaskStatus.Success;
        }
        else
        {
            return TaskStatus.Failure;
        }
	}
}